using UnityEngine;
using System.Collections;

public class DeathZone : MonoBehaviour {

    Vector3 startPosition;
    Quaternion startRotation;

	void Start () 
    {
        /// Recuperation de l'objet player
        GameObject player = GameObject.FindGameObjectWithTag("Player");
        if (player == null)
        {
            /// Si aucun objet n'a de tag player on quitte la methode Start
            Debug.LogError("Impossible de trouver le player, verifiez que l'objet player a un bien le Tag Player");
            return;
        }
        /// On enregistre la position et la rotation d'origine du player
        this.startPosition = player.transform.position;
        this.startRotation = player.transform.rotation;
	}

    void OnTriggerEnter(Collider other)
    {
        /// Si l'objet qui entre en contact avec le trigger est le player
        if (other.tag == "Player")
        {
            /// on replace le player a sa position initial.
            Transform playerTransform = other.transform;
            playerTransform.position = this.startPosition;
            playerTransform.rotation = this.startRotation;
        }
    }
}
